package com.lucy.viewer.controller;

import com.lucy.viewer.constant.ViewerServiceEnum;
import com.lucy.viewer.service.ViewerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * @author kindear
 * 回调函数接口
 */
@Slf4j
@RestController
@RequestMapping("viewer")
@Api(tags = "回调函数")
@AllArgsConstructor
public class CallBackController {

    List<ViewerService> services;
    // office 编辑回调
    @Deprecated
    @ApiIgnore
    @PostMapping("editor/callback")
    @ApiOperation(value = "office文件编辑回调",notes = "")
    public Object editorCallback(@RequestBody Map<String,Object> map){
        log.info("执行编辑回调");
        for(ViewerService service:services){
            if (service.service().equals(ViewerServiceEnum.ONLY_OFFICE)){
                return service.editorCallBack(map);
            }
        }
        return null;
    }

    @ApiIgnore
    @PostMapping("onlyoffice/callback")
    @ApiOperation(value = "onlyoffice文件编辑回调",notes = "")
    public Object officeCallback(@RequestBody Map<String,Object> map){
        log.info("执行编辑回调");
        for(ViewerService service:services){
            if (service.service().equals(ViewerServiceEnum.ONLY_OFFICE)){
                return service.editorCallBack(map);
            }
        }
        return null;
    }

    @Deprecated
    @ApiIgnore
    @PostMapping("callback/md")
    @ApiOperation(value = "markdown文件编辑回调",notes = "")
    public Object markdownCallback(@RequestBody Map<String,Object> map){
        //log.info("MD文件编辑回调");
        for(ViewerService service:services){
            if (service.service().equals(ViewerServiceEnum.VDITOR)){
                return service.editorCallBack(map);
            }
        }
        return null;
    }

    @ApiIgnore
    @PostMapping("vditor/callback")
    @ApiOperation(value = "vditor编辑回调",notes = "")
    public Object vditorEditCallback(@RequestBody Map<String,Object> map){
        log.info("MD文件编辑回调");
        for(ViewerService service:services){
            if (service.service().equals(ViewerServiceEnum.VDITOR)){
                return service.editorCallBack(map);
            }
        }
        return null;
    }

}
